<%@ page import="pe.com.mowa.siscobsms.bean.*" %>
<%@ page import="pe.com.mowa.siscobsms.datos.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.sql.Date"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script type="text/javascript">

function agregaPago()
{
document.getElementById("frmpago").action="popupTarifa.jsp?txtmonto="+document.getElementById("txtmonto");
document.getElementById("evento").value=0;
//reporte_pagos
//alert('agregando pago');

document.getElementById("frmpago").submit();
}

function actualiza_reporte_pagos()
{
window.opener.reporte_pagos(document.getElementById("idprestamo").value);
}

function abortaPago()
{
//window.opener.reporte_pagos();
window.close();
}

</script>

	<meta charset="utf-8">

	<link rel="stylesheet" href="css/jquery.ui.all.css">
	<link rel="stylesheet" href="css/demos.css">
		
	<script src="js/jquery-1.6.2.js"></script>
    <script src="js/jquery.ui.core.js"></script>
	<script src="js/jquery.ui.widget.js"></script>
	<script src="js/jquery.ui.datepicker.js"></script>


<script>
	$(function() {
		$( "#datepicker" ).datepicker();
	});
	</script>

<style type="text/css">
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
</style>
</head>
<body>

<form id="frmpago">



<div class="demo">

<input id="idprestamo" name="idprestamo" type="hidden" value="<%= request.getParameter("idprestamo")%>">
<p>Monto: <input id="txtmonto" name="txtmonto" type="text" value="<%= request.getParameter("txtmonto")%>"></p>
<p>Fecha: <input id="datepicker" name="datepicker" type="text"></p>
<input id="evento" name="evento" type="hidden">


</div><!-- End demo -->

<div style="display: none;" class="demo-description">
<p>The datepicker is tied to a standard form input field.  Focus on the input (click, or use the tab key) to open an interactive calendar in a small overlay.  Choose a date, click elsewhere on the page (blur the input), or hit the Esc key to close. If a date is chosen, feedback is shown as the input's value.</p>
</div><!-- End demo-description -->

<%
	int idprestamo=0;
try
{
idprestamo  = Integer.parseInt(request.getParameter("idprestamo"));
}
catch(Exception e)
{
	}

if (idprestamo==0)
{
	out.print("<script>");
	out.print("alert('Debe seleccionar un proyecto');");
	out.print("window.close();");
	out.print("</script>");

}

conTarifa cp = new conTarifa();
tarifa pago = new tarifa();
proyecto pres =  new proyecto();
pres.setId(idprestamo);
String txtfecha="";
java.sql.Date fecha= null ;

try{
 txtfecha  = request.getParameter("datepicker");


  SimpleDateFormat template = 	new SimpleDateFormat("yyyy-MM-dd"); 

  java.util.Date enddate = new java.util.Date(txtfecha); 
  
  fecha = java.sql.Date.valueOf(template.format(enddate)); 

}
catch(Exception e)
{
	}
// 0 .. insert
// 1 .. update
// 2 .. delete
String evento  = request.getParameter("evento");

float monto =0;
try
{
	monto = Float.parseFloat(request.getParameter("txtmonto"));	
}
catch(Exception e)
{
	
}

if (monto==0)
{
	out.print("<script>");
	out.print("alert('Debe seleccionar un prestamo');");
	out.print("window.close();");
	out.print("</script>");

}

try
{
		if (evento.equals("0"))
		{
	pago.setFecha(fecha);
	pago.setPrestamo(pres);
	pago.setMonto(monto); 
	cp.setPago(pago);
	
	out.print("<script> actualiza_reporte_pagos();");
	out.print("if (!confirm('El pago fue agregado,Desea agregar otro?')) window.close();");
	out.print("</script>");
		}
}
catch( Exception e)
{
	
}
%> 
<table align="center" width="100%" border="1">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>

  <tr>
    <td>&nbsp;</td>
    <td><a href="#" onclick="agregaPago();">AGREGAR</a></td>
    <td>&nbsp;</td>
    <td><a href="#" onclick="abortaPago();">CANCELAR</a></td>
    <td>&nbsp;</td>
  </tr>

</table>



</form>


</body>



<script type="text/javascript">
<!--
var currentTime = new Date();
var fecha=(currentTime.getMonth()+1)+"/"+currentTime.getDate()+"/"+currentTime.getFullYear();
document.getElementById("datepicker").value=fecha;
//-->
</script>


</html>